package com.vogue.supplymall.match.domain.service.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.vogue.ssm.database.dao.BaseDao;
import com.vogue.ssm.database.util.DealStatus;
import com.vogue.supplymall.account.domain.model.User;
import com.vogue.supplymall.account.domain.service.BaseCodeService;
import com.vogue.supplymall.account.domain.service.BaseRegistinfoService;
import com.vogue.supplymall.account.domain.service.UserService;
import com.vogue.supplymall.common.domain.tool.BeanToolsUtils;
import com.vogue.supplymall.common.domain.tool.MessageSourceUtils;
import com.vogue.supplymall.match.domain.dao.MatchOrganDao;
import com.vogue.supplymall.match.domain.dto.AddressesDTO;
import com.vogue.supplymall.match.domain.dto.BaseDTO;
import com.vogue.supplymall.match.domain.dto.BuerEnterpriseDTO;
import com.vogue.supplymall.match.domain.dto.BuyerOrganDTO;
import com.vogue.supplymall.match.domain.dto.BuyerOrganDetailDTO;
import com.vogue.supplymall.match.domain.dto.EnterpriseDTO;
import com.vogue.supplymall.match.domain.dto.GoodsPropertiesDTO;
import com.vogue.supplymall.match.domain.dto.GoodsPropertiesDetailsDTO;
import com.vogue.supplymall.match.domain.dto.GoodsproPertiesValueDTO;
import com.vogue.supplymall.match.domain.dto.OrderPullDTO;
import com.vogue.supplymall.match.domain.dto.OrderPushDTO;
import com.vogue.supplymall.match.domain.dto.PcrapDTO;
import com.vogue.supplymall.match.domain.dto.PcrapdDTO;
import com.vogue.supplymall.match.domain.dto.PfcrapDTO;
import com.vogue.supplymall.match.domain.dto.ProductCustomerDataDTO;
import com.vogue.supplymall.match.domain.dto.ProductCustomerDetailsDTO;
import com.vogue.supplymall.match.domain.dto.ProductCustomerGoodsDTO;
import com.vogue.supplymall.match.domain.dto.ProductDTO;
import com.vogue.supplymall.match.domain.dto.ProductDataDTO;
import com.vogue.supplymall.match.domain.dto.ProductPriceDTO;
import com.vogue.supplymall.match.domain.dto.ProductPriceDataDTO;
import com.vogue.supplymall.match.domain.dto.ProductPricePertiesValueDTO;
import com.vogue.supplymall.match.domain.dto.ProductPricePropertiesDTO;
import com.vogue.supplymall.match.domain.dto.ProductPricePropertiesDetailsDTO;
import com.vogue.supplymall.match.domain.dto.PullShopOfCustomerDTO;
import com.vogue.supplymall.match.domain.dto.SellerOrganDTO;
import com.vogue.supplymall.match.domain.dto.StoreDTO;
import com.vogue.supplymall.match.domain.dto.UserDTO;
import com.vogue.supplymall.match.domain.model.MatchOrgan;
import com.vogue.supplymall.match.domain.service.ColValidateService;
import com.vogue.supplymall.match.domain.service.MatchOrganService;
import com.vogue.supplymall.order.domain.service.OrderPullService;
import com.vogue.supplymall.shop.common.CodeTransformUtils;
import com.vogue.supplymall.shop.domain.model.Product;
import com.vogue.supplymall.shop.domain.model.Shop;
import com.vogue.supplymall.shop.domain.service.ProductService;
import com.vogue.supplymall.shop.domain.service.ShopService;

@Service("colValidateService")
@Transactional
public class ColValidateServiceImpl extends BaseServiceImpl<MatchOrgan, Long> implements ColValidateService{
	@Resource
	private MatchOrganDao matchOrganDao;
	
	@Autowired
	private MessageSourceUtils msu;
	
	@Resource
	private BaseCodeService baseCodeService;
	
	@Resource
	private CodeTransformUtils codeTransformUtils;
	@Resource
	private MatchOrganService matchOrganService;
	@Resource
	private ShopService shopService;
	@Resource 
	private ProductService productService;
	@Resource
	private BaseRegistinfoService baseRegistinfoService;
	@Resource
	private UserService userService;
	@Resource
	private OrderPullService orderPullService;
	
	private static SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	public ColValidateServiceImpl(BaseDao<MatchOrgan, Long> baseDao) {
		super(baseDao);
		matchOrganDao=(MatchOrganDao) baseDao;
	}

	@Override
	public <T> List<Map<String, Object>> safetyValidate(BaseDTO<T> baseDTO,boolean entFlag,String checkType) {
		List<Map<String, Object>> errList = new ArrayList<>();
		List<String> infoList=new ArrayList<>();
		if(baseDTO == null) {
			infoList.add(msu.getMessage("match.validate.dtoisnull", new String[] {"data"}));
			Map<String, Object> map=this.setValueForErrMap(msu.getMessage("global.system.datasource", null), "", infoList,dsNoneError);
			errList.add(map);
		}else {
			Long code=baseDTO.getRegistercode();
			String tel=baseDTO.getRegistertel();
			String enterpriseId=baseDTO.getEnterpriseid();
			
			//字段非空验证
			if(code==null) {
				infoList.add(msu.getMessage("match.validate.syscodeIsNull", null));
				Map<String, Object> map=this.setValueForErrMap(msu.getMessage("global.system.syscode", null), "",infoList,commonError);
				errList.add(map);
			}
			if(tel==null) {
				infoList.add(msu.getMessage("match.validate.telIsNull", null));
				Map<String, Object> map=this.setValueForErrMap(msu.getMessage("global.system.tel", null), "",infoList,commonError);
				errList.add(map);
			}
			if(enterpriseId==null) {
				infoList.add(msu.getMessage("match.validate.entIdIsNull", null));
				Map<String, Object> map=this.setValueForErrMap(msu.getMessage("global.system.entId", null), "",infoList,commonError);
				errList.add(map);
			}
		
			if(errList.size()==0){
				//验证注册号是否有效
				Long sysCodeId =baseCodeService.checkSysCodeValidity(code);
				if(sysCodeId==0) {
					infoList.add(msu.getMessage("match.validate.syscodeNotExist", new String[] {code.toString()}));
					Map<String, Object> map=this.setValueForErrMap(msu.getMessage("global.system.syscode", null), "", infoList,commonError);
					errList.add(map);
				}else {
					//验证电话号是否是注册时手机号
					String newTel=baseRegistinfoService.findTelBySysCodeId(sysCodeId);
					if(StringUtils.isNotBlank(newTel)) {
						if(!tel.equals(newTel)) {
							infoList.add(msu.getMessage("match.validate.telNotExist", new String[] {tel}));
							Map<String, Object> map=this.setValueForErrMap(msu.getMessage("global.system.tel", null), "", infoList,commonError);
							errList.add(map);
						}
					}else {
						infoList.add(msu.getMessage("match.validate.telNotFind", new String[] {tel}));
						Map<String, Object> map=this.setValueForErrMap(msu.getMessage("global.system.tel", null), "", infoList,commonError);
						errList.add(map);
					}
					
					//判断企业id是否存在，若存在，判断是否正确,拉取订单和推送订单不需要判断
					if(checkType.equals("orderBill")) {
						DealStatus.kacha();
					}
					List<String> entList=matchOrganDao.getAllOrganIdBySysCode(sysCodeId);
					if(entList.size()>0) {
						boolean codeFlag=false;
						for(String matchId:entList) {
							if(matchId.equals(enterpriseId)) {	//说明注册号与企业号对应，注册号绑定无误，否则说明注册号已被占用
								codeFlag=true;
							}
						}
						
						if(!codeFlag) {
							infoList.add(msu.getMessage("match.validate.codeOccupyOrEntIdError", null));
							Map<String, Object> map=this.setValueForErrMap(msu.getMessage("global.system.entId", null), "", infoList,commonError);
							errList.add(map);
						}
						
					}else {	//说明还没有上传企业
						if(!entFlag) { 	//不是企业上传接口
							infoList.add(msu.getMessage("match.validate.entIdNotExist", new String[] {enterpriseId}));
							Map<String, Object> map=this.setValueForErrMap(msu.getMessage("global.system.entId", null), "", infoList,commonError);
							errList.add(map);
						}
					}
					
				}
				
			}
			
		}
		
		return errList;
	}

	@Override
	public List<Map<String, Object>> enterpriseValidate(BaseDTO<EnterpriseDTO> baseDTO) throws Exception{
		List<Map<String, Object>> errList = new ArrayList<>();
		EnterpriseDTO entDTO = baseDTO != null ? baseDTO.getData() : null;
		//全局安全验证
		errList=this.safetyValidate(baseDTO, true, "company");
		if(errList.size()==0) {	
			if(entDTO == null) {
				List<String> infoList=new ArrayList<>();
				infoList.add(msu.getMessage("match.validate.dtoisnull", new String[] {"data"}));
				Map<String, Object> map=this.setValueForErrMap(msu.getMessage("global.system.datasource", null), "", infoList,dsNoneError);
				errList.add(map);
			}else {
				//非空字段的验证
				errList=this.checkEnterpriseData(baseDTO);
			}	
		}
		
		return errList;
	}

	@Override
	public List<Map<String, Object>> pullShopOfCustomerValidate(BaseDTO<PullShopOfCustomerDTO> baseDTO)
			throws Exception {
		List<Map<String, Object>> errList = new ArrayList<>();
		PullShopOfCustomerDTO pscDTO = baseDTO != null ? baseDTO.getData() : null;
		//全局安全验证
		errList=this.safetyValidate(baseDTO, true, "company");
		if(errList.size()==0) {	
			if(pscDTO == null) {
				List<String> infoList=new ArrayList<>();
				infoList.add(msu.getMessage("match.validate.dtoisnull", new String[] {"data"}));
				Map<String, Object> map=this.setValueForErrMap(msu.getMessage("global.system.datasource", null), "", infoList,dsNoneError);
				errList.add(map);
			}
//			else {
//				//非空字段的验证
//				errList=this.checkPullShopOfCustomerData(baseDTO);
//			}	
		}
		
		return errList;
	}

	@Override
	public List<Map<String, Object>> pushCustomerRelationAndPayModeValidate(BaseDTO<PfcrapDTO> baseDTO)
			throws Exception {
		Map<String, Object> errorMap=new HashMap<>();
		List<Map<String, Object>> errList = new ArrayList<>();
		PfcrapDTO pfcrapDTO=baseDTO != null ? baseDTO.getData() : null;
		
		//全局安全验证
		errList=this.safetyValidate(baseDTO, true, "company");
		if(errList.size()==0) {	
			if(pfcrapDTO == null) {
				List<String> infoList=new ArrayList<>();
				infoList.add(msu.getMessage("match.validate.dtoisnull", new String[] {"data"}));
				Map<String, Object> map=this.setValueForErrMap(msu.getMessage("global.system.datasource", null), "", infoList,dsNoneError);
				errList.add(map);
			}else {
						//非空字段的验证
						errList=this.checkPushShopOfCustomerData(baseDTO);
			}	
		}
		
		return errList;
	}

	@Override
	public List<Map<String, Object>> sellerOrganValidate(BaseDTO<List<SellerOrganDTO>> baseDTO)  throws Exception{
		List<SellerOrganDTO> soDTOList = baseDTO != null ? baseDTO.getData() : null;
		List<Map<String, Object>> errList = new ArrayList<>();
		
		//全局安全验证
		errList=this.safetyValidate(baseDTO, false,"sellerOrgan");
		if(errList.size()==0) {	
			
			//要检查的数据源是空直接记录错误
			if(soDTOList == null) {
				List<String> infoList=new ArrayList<>();
				infoList.add(msu.getMessage("match.validate.dtoisnull", new String[] {"data"}));
				Map<String, Object> map=this.setValueForErrMap(msu.getMessage("global.system.datasource", null), "", infoList,dsNoneError);
				errList.add(map);
			}else {
				//非空字段的验证
				errList=this.checkSellerOrganData(baseDTO);
				
				for(SellerOrganDTO dto : soDTOList) {
					//1、地址类信息要与商城的代码一致，不一致则返回错误信息
					errList=this.checkAdministrativeArea(dto, soDTOList,errList);
					
				}
			}
		}
		
		return errList;
			
	}

	@Override
	public List<Map<String, Object>> buyerOrganValidate(BaseDTO<BuyerOrganDTO> baseDTO)  throws Exception{
		List<Map<String, Object>> errList = new ArrayList<>();
		//全局安全验证
		errList=this.safetyValidate(baseDTO, false,"buyerOrgan");
		if(errList.size()==0) {			
			BuyerOrganDTO organDTO = baseDTO != null ? baseDTO.getData() : null;
			if(organDTO == null) {
				List<String> infoList=new ArrayList<>();
				infoList.add(msu.getMessage("match.validate.dtoisnull", new String[] {"data"}));
				Map<String, Object> map=this.setValueForErrMap(msu.getMessage("global.system.datasource", null), "", infoList,dsNoneError);
				errList.add(map);
			}else {
				//非空字段的验证
				errList=this.checkBuyerOrganData(baseDTO);
				
				List<BuyerOrganDetailDTO> organList = organDTO.getOrgan();
				if(organList == null) {
					List<String> infoList=new ArrayList<>();
					infoList.add(msu.getMessage("match.validate.dtoisnull", new String[] {"organ"}));
					Map<String, Object> map=this.setValueForErrMap(msu.getMessage("global.system.datasource", null), "", infoList,dsNoneError);
					errList.add(map);
				}			
			}	
		}
		return errList;
	}

	@Override
	public List<Map<String, Object>> buyerValidate(BaseDTO<List<UserDTO>> baseDTO)  throws Exception{
		List<Map<String, Object>> errList = new ArrayList<>();
		
		//全局安全验证
		errList=this.safetyValidate(baseDTO, false,"buyer");
		if(errList.size()==0) {		
			List<UserDTO> userDTOs=baseDTO.getData();
			
			if(userDTOs==null) {
				List<String> infoList=new ArrayList<>();
				infoList.add(msu.getMessage("match.validate.dtoisnull", new String[] {"data"}));
				Map<String, Object> map=this.setValueForErrMap(msu.getMessage("global.system.datasource", null), "",infoList,dsNoneError);
				errList.add(map);
			}else {
				//非空字段的验证
				errList=this.checkUserData(baseDTO);
				
			}

			
		}
		return errList;
	}
	
	
	
	@Override
	public List<Map<String, Object>> productValidate(BaseDTO<List<ProductDataDTO>> baseDTO) throws Exception{
		List<Map<String, Object>> errList=new ArrayList<>();
		
		//全局安全验证
		errList=this.safetyValidate(baseDTO, false,"product");
		if(errList.size()==0) {		
			List<ProductDataDTO> productDataDTOs=baseDTO.getData();
			Long sysCodeId =baseCodeService.checkSysCodeValidity(baseDTO.getRegistercode());
			
			//非空字段的验证
			errList=this.checkProductInfoData(baseDTO);
			
			//遍历商品信息，进行验证
			for(ProductDataDTO productDataDTO:productDataDTOs) {
				
				String organId=productDataDTO.getShopId();
				
				List<ProductDTO> productDTOs=productDataDTO.getDetails();
				for(ProductDTO productDTO:productDTOs) {
					
					//商品名和id
					String productName=productDTO.getName();
					String matchId=productDTO.getMatchid();
					
					//单位名称不能重复
				    List<GoodsPropertiesDTO> goodsPropertiesDTOs=productDTO.getGoodsproperties();
				    errList=this.checkProductUnit(errList, goodsPropertiesDTOs, productName, matchId);

				}
				
				//检查商品所在的店铺是否已上传
				this.checkShopIsExist(errList, organId, sysCodeId);
			
			}
				
		}
	
		return errList;
	}

	/**
	 * 商品属性和商品属性组合对应的值的oper值应该一致
	 * 此方法只支持单位一个属性，如果有多个属性，需要重新写方法
	 */
	public void checkPPOperUniformity(List<Map<String, Object>> errList,ProductDTO productDTO) {
		List<GoodsPropertiesDTO> goodsPropertiesDTOs=productDTO.getGoodsproperties();
		List<GoodsPropertiesDetailsDTO> goodsPropertiesDetailsDTOs=goodsPropertiesDTOs.get(0).getDetails();
		List<GoodsproPertiesValueDTO> goodsproPertiesValueDTOs=productDTO.getGoodspropertiesvalue();
		
		for(GoodsPropertiesDetailsDTO gpdDTO:goodsPropertiesDetailsDTOs) {
			String pertiesid=gpdDTO.getPertiesid();
			int gpdOper=gpdDTO.getOper();
			
			for(GoodsproPertiesValueDTO gpvDTO:goodsproPertiesValueDTOs) {
				String ids=gpvDTO.getIds();
				String id=ids.replace(",", "");
				int gpvOper=gpvDTO.getOper();
				
				if(pertiesid.equals(id)) {
					if(gpdOper!=gpvOper) {
						List<String> infoList=new ArrayList<>();
						infoList.add(msu.getMessage("match.validate.ppOperUniformity",null));
						Map<String, Object> errMap=this.setValueForErrMap(productDTO.getName(),productDTO.getMatchid(),infoList,dataError);
						errList.add(errMap);
					}
				}
				
			}
			
		}
		
	}
	
	/**
	 * 单位名称不能重复
	 */
	public List<Map<String, Object>> checkProductUnit(List<Map<String, Object>> errList,List<GoodsPropertiesDTO> goodsPropertiesDTOs,
			String productName,String matchId){
		List<String> nameList=new ArrayList<>();
		
		for(GoodsPropertiesDTO gpDTO:goodsPropertiesDTOs) {
			List<GoodsPropertiesDetailsDTO> goodsPropertiesDetailsDTOs=gpDTO.getDetails();
			for(GoodsPropertiesDetailsDTO gpdDTO:goodsPropertiesDetailsDTOs) {
				String unitName=gpdDTO.getPertiesname();
				
				if(nameList.contains(unitName)) {
					List<String> infoList=new ArrayList<>();
					infoList.add(msu.getMessage("match.validate.unitNameRepeat", new String[] {unitName}));
					Map<String, Object> errMap = this.setValueForErrMap(productName, matchId,infoList,commonError);
					errList.add(errMap);
				}
				
				nameList.add(unitName);
			}
		}
		
		return errList;
	}
	
	/**
	 * 检查商品所在的店铺是否已上传
	 */
	public Map<String, Object> checkShopIsExist(List<Map<String, Object>> errList,String organId,Long sysCodeId){
		MatchOrgan mo=new MatchOrgan();
		Map<String, Object> resultMap=new HashMap<>();
		
		mo=matchOrganDao.getMatchOrganByMatchId(sysCodeId,organId);
		if(mo==null) {
			List<String> infoList=new ArrayList<>();
			infoList.add(msu.getMessage("match.validate.shopNone", null));
			Map<String, Object> errMap = this.setValueForErrMap(msu.getMessage("global.system.shop", null), organId,infoList,commonError);
			errList.add(errMap);
		}
		
		return resultMap;
	}
	
	//商品验证结果整理
	public List<Map<String, Object>> arrangeResultOfCheckProduct(List<Map<String, Object>> errList,List<Map<String, String>> resultList,String message,String type){
		for(Map<String, String> errMap:resultList) {
			List<String> infoList=new ArrayList<>();
			infoList.add(msu.getMessage(message, null));
			Map<String, Object> map=this.setValueForErrMap(errMap.get("productName"), errMap.get("matchId"),infoList,type);
			errList.add(map);
		}
			
		return errList;
	}
	
	@Override
	public List<Map<String, Object>> producPriceValidate(BaseDTO<List<ProductPriceDataDTO>> baseDTO) throws Exception {
		List<Map<String, Object>> errList=new ArrayList<>();
		
		//全局安全验证
		errList=this.safetyValidate(baseDTO, false,"productPrice");
		if(errList.size()==0) {		
			//非空字段的验证
			errList=this.checkProductPriceInfoData(baseDTO);
			
			//开始时间和结束时间的验证,开始时间不能大于结束时间，时间段之间不能有重叠
			errList=this.checkDateOfProductPrice(errList, baseDTO);
		}
					

		return errList;
	}

	@Override
	public List<Map<String, Object>> productCustomerValidate(BaseDTO<List<ProductCustomerDataDTO>> baseDTO)
			throws Exception {		
		List<Map<String, Object>> errList=new ArrayList<>();
		
		//全局安全验证
		errList=this.safetyValidate(baseDTO, false,"productCustomer");
		
		if(errList.size()==0) {	
			//非空字段的验证
			errList=this.checkProductCustomerInfoData(baseDTO);
			
			//客户注册号验证，要保证传过来的客户注册号存在，且不能与自己的注册号相同
			this.checkCustomerSyscode(baseDTO, errList);
		}
		
		return errList;
	}

	@Override
	public List<Map<String, Object>> orderPushValidate(BaseDTO<List<OrderPushDTO>> baseDTO) throws Exception {
		List<Map<String, Object>> errList=new ArrayList<>();
		List<String> onList=new ArrayList<>();
		
		//全局安全验证
		errList=this.safetyValidate(baseDTO, false,"orderBill");
		
		if(errList.size()==0) {	
			//非空字段的验证
			this.checkOrderPushColNull(baseDTO, errList);
			
			List<OrderPushDTO> opDTOs=baseDTO.getData();
			
			//type值的验证
//			for(OrderPushDTO opDTO:opDTOs) {
//				int type=opDTO.getType();
//				String orderNums=opDTO.getOrderNums();
//				String[] onArr=orderNums.split(",");
//				onList=Arrays.asList(onArr);
//						
//				if(type!=0&&type!=1&&type!=2&&type!=3) {
//					List<String> infoList=new ArrayList<>();
//					infoList.add(msu.getMessage("match.validate.orderPushTypeError",null));
//					Map<String, Object> map=this.setValueForErrMap("订单", null,infoList,dataError);
//					errList.add(map);
//				}
//			}
			
			//订单号合法性验证
//			if(onList.size()>0) {
//				List<Map<String, Object>> orderNumList=orderPullService.findOrderNumsByOrderNums(onList);
//				if(onList.size()!=orderNumList.size()) {
//					List<String> existList=new ArrayList<>();
//					for(Map<String, Object> map:orderNumList) {
//						String orderNum=(String) map.get("ordernumber");
//						existList.add(orderNum);
//					}
//					
//					for(String on:onList) {
//						if(!existList.contains(on)) {
//							List<String> infoList=new ArrayList<>();
//							infoList.add(msu.getMessage("match.validate.orderNumNotExist",new String[] {on}));
//							Map<String, Object> map=this.setValueForErrMap("订单", on,infoList,dataError);
//							errList.add(map);
//						}
//					}
//					
//				}
//			}
		}
		
		return errList;
	}

	/**
	 * 客户注册号验证
	 */
	public List<Map<String, Object>> checkCustomerSyscode(BaseDTO<List<ProductCustomerDataDTO>> baseDTO,List<Map<String, Object>> errList) {
		Long syscode=baseDTO.getRegistercode();
		List<Long> codeList=new ArrayList<>();
		String cusCodes="";
		List<ProductCustomerDataDTO> productCustomerDataDTOs=baseDTO.getData();
		for(ProductCustomerDataDTO pcdDTO:productCustomerDataDTOs) {
			List<ProductCustomerDetailsDTO> pcdList=pcdDTO.getDetails();
			for(ProductCustomerDetailsDTO pcdeDTO:pcdList) {
				Long cussyscode=pcdeDTO.getCussyscode();
				if(cussyscode==syscode) {
					List<String> infoList=new ArrayList<>();
					infoList.add(msu.getMessage("match.validate.cusSyscodeSame",new String[] {cussyscode+""}));
					Map<String, Object> map=this.setValueForErrMap(pcdeDTO.getCustomername(), cussyscode+"",infoList,commonError);
					errList.add(map);
				}else {
					if(!codeList.contains(cussyscode)) {
						codeList.add(cussyscode);
						cusCodes+=cussyscode+",";
					}
					
				}
			}
		}
		
		if(StringUtils.isNotBlank(cusCodes)) {
			cusCodes=cusCodes.substring(0,cusCodes.length()-1);
			List<Long> existCodes=baseCodeService.checkSysCodeExist(cusCodes);
			if(existCodes.size()>0&&existCodes.get(0)!=null) {
				for(Long code:codeList) {
					if(!existCodes.contains(code)) {
						List<String> infoList=new ArrayList<>();
						infoList.add(msu.getMessage("match.validate.cusSyscodeNotExist",new String[] {code+""} ));
						Map<String, Object> map=this.setValueForErrMap("客户注册号", code+"",infoList,commonError);
						errList.add(map);
					}
				}
			}else {
				List<String> infoList=new ArrayList<>();
				infoList.add(msu.getMessage("match.validate.cusSyscodeNotExist", new String[] {cusCodes+""}));
				Map<String, Object> map=this.setValueForErrMap("客户注册号", cusCodes,infoList,commonError);
				errList.add(map);
			}
		}
		
		return null;
	}

	/**
	 * 推送订单非空字段验证
	 */
	public  List<Map<String, Object>> checkOrderPushColNull(BaseDTO<List<OrderPushDTO>> baseDTO,List<Map<String, Object>> errList)
		throws Exception{
		Map<String, Object> errorMap=new HashMap<>();
		List<String> nullList=new ArrayList<>();
		List<String> colList=new ArrayList<>();
		
		List<OrderPushDTO> opList=baseDTO.getData();
		
		//得到要验证非空的字段
		String[] nullCol=new String[] {"type","orderNums"};

		for(OrderPushDTO opDTO:opList) {
			//对字段进行验证
			nullList=BeanToolsUtils.checkObjFieldIsNull(opDTO, nullCol);
					
			if(nullList.size()>0) {
				colList=this.joinHintMessage(colList, nullList);
			}		
			
			if(colList.size()>0) {
				errorMap=this.setValueForErrMap("订单",null,colList,commonError);
				errList.add(errorMap);
			}
		}	
		
		return errList;
	}
	
	/**
	 * 装配具体的错误信息
	 */
	@Override
	public Map<String, Object> setValueForErrMap(String name,String id,List<String> info,String type){
		if(StringUtils.isEmpty(name)) {
			name="";
		}
		
		if(StringUtils.isEmpty(id)) {
			id="";
		}
	
		Map<String, Object> map=new HashMap<>();
		map.put(errType, type);
		map.put(errName, name);
		map.put(errId, id);
		map.put(errInfo, info);
		return map;
	}
	
	//装配错误商品信息
	public Map<String, String> setValueOfErrProduct(String productName,String matchId){
		Map<String, String> map=new HashMap<>();
		map.put("productName", productName);
		map.put("matchId", matchId);
		
		return map;
		
	}

	/**
	 * 企业信息非空字段验证
	 */
	public List<Map<String, Object>> checkEnterpriseData(BaseDTO<EnterpriseDTO> baseDTO) throws Exception{
		List<Map<String, Object>> errList=new ArrayList<>();
		Map<String, Object> errorMap=new HashMap<>();
		List<String> nullList=new ArrayList<>();
		List<String> colList=new ArrayList<>();
		
		EnterpriseDTO enterpriseDTO=baseDTO.getData();
		
		//得到要验证非空的字段
		String[] nullCol=new String[] {"orgname","orgcode","matchid","tpsystem","type","stopflag","waitingOrder"};

		//对字段进行验证
		nullList=BeanToolsUtils.checkObjFieldIsNull(enterpriseDTO, nullCol);
				
		if(nullList.size()>0) {
			colList=this.joinHintMessage(colList, nullList);
		}		
		
		if(colList.size()>0) {
			errorMap=this.setValueForErrMap(enterpriseDTO.getOrgname(),enterpriseDTO.getMatchid(),colList,commonError);
			errList.add(errorMap);
		}
	
		return errList;
	}
	
//	/**
//	 * 拉取门店订单信息非空字段验证
//	 */
//	public List<Map<String, Object>> checkPullShopOfCustomerData(BaseDTO<PullShopOfCustomerDTO> baseDTO) throws Exception{
//		List<Map<String, Object>> errList=new ArrayList<>();
//		Map<String, Object> errorMap=new HashMap<>();
//		List<String> nullList=new ArrayList<>();
//		List<String> colList=new ArrayList<>();
//		
//		PullShopOfCustomerDTO enterpriseDTO=baseDTO.getData();
//		
//		//得到要验证非空的字段
//		String[] nullCol=new String[] {"syscodes"};
//
//		//对字段进行验证
//		nullList=BeanToolsUtils.checkObjFieldIsNull(enterpriseDTO, nullCol);
//				
//		if(nullList.size()>0) {
//			colList=this.joinHintMessage(colList, nullList);
//		}		
//		
//		if(colList.size()>0) {
//			errorMap=this.setValueForErrMap("客户",null,colList,commonError);
//			errList.add(errorMap);
//		}
//	
//		return errList;
//	}
	
	/**
	 * 推送门店支付方式验证
	 */
	public List<Map<String, Object>> checkPushShopOfCustomerData(BaseDTO<PfcrapDTO> baseDTO) throws Exception{
		List<Map<String, Object>> errList=new ArrayList<>();
		Map<String, Object> errorMap=new HashMap<>();
		List<String> nullList=new ArrayList<>();
		List<String> colList=new ArrayList<>();
		
		PfcrapDTO pfcrapDTO=baseDTO.getData();
		
		//得到要验证非空的字段
		String[] pfNullCol=new String[] {"buysyscode","buyname"};
		String[] pcdNullCol=new String[] {"buyorganid","buymatchid","buyorganname","paymode"};

		for(PcrapDTO pcrDTO:pfcrapDTO.getBuyerInfo()) {
			//对字段进行验证
			nullList=BeanToolsUtils.checkObjFieldIsNull(pcrDTO, pfNullCol);
					
			if(nullList.size()>0) {
				colList=this.joinHintMessage(colList, nullList);
			}		
			
			if(colList.size()>0) {
				errorMap=this.setValueForErrMap(pcrDTO.getBuyname(),null,colList,commonError);
				errList.add(errorMap);
			}
			
			for(PcrapdDTO pdDTO:pcrDTO.getDetail()) {
				//对字段进行验证
				nullList=BeanToolsUtils.checkObjFieldIsNull(pdDTO, pcdNullCol);
						
				if(nullList.size()>0) {
					colList=this.joinHintMessage(colList, nullList);
				}		
				
				if(colList.size()>0) {
					errorMap=this.setValueForErrMap(pdDTO.getBuyorganname(),null,colList,commonError);
					errList.add(errorMap);
				}
			}
			
		}
	
		return errList;
	}
	
	/**
	 * 买家机构信息非空字段验证
	 */
	public List<Map<String, Object>> checkBuyerOrganData(BaseDTO<BuyerOrganDTO> baseDTO) throws Exception {
		List<Map<String, Object>> errList=new ArrayList<>();
		Map<String, Object> errorMap=new HashMap<>();
		List<String> nullList=new ArrayList<>();
		List<String> storeNullList=new ArrayList<>();
		List<String> addressNullList=new ArrayList<>();
		List<String> colList=new ArrayList<>();
		
		BuyerOrganDTO dataMap=baseDTO.getData();
		BuerEnterpriseDTO buerEnterpriseDTO=dataMap.getEnterprise();
		List<BuyerOrganDetailDTO> buyerOrganDetailDTOs=dataMap.getOrgan();
		
		//得到要验证非空的字段
		String[] nullCol=new String[] {"orgname","orgcode","matchid","type","parentid","store","enterprise","addresses","disabledflag","entname"};
		String[] storeNullCol=new String[] {"orgname","orgcode","matchid","type","disabledflag"};
		String[] adressNullCol=new String[] {"addr","tel","linkman","area","province","city"};
		String[] enterpriseNullCol=new String[] {"orgname","orgcode","matchid"};
		
		//对企业字段进行验证
		nullList=BeanToolsUtils.checkObjFieldIsNull(buerEnterpriseDTO, enterpriseNullCol);
		if(nullList.size()>0) {
			colList=this.joinHintMessage(colList, nullList);
		}
		
		for(BuyerOrganDetailDTO buyerOrganDetailDTO:buyerOrganDetailDTOs) {
			//对店铺字段进行验证
			nullList=BeanToolsUtils.checkObjFieldIsNull(buyerOrganDetailDTO, nullCol);			
			if(nullList.size()>0) {
				colList=this.joinHintMessage(colList, nullList);
			}
			
			//对仓库字段进行验证
			List<StoreDTO> storeList=buyerOrganDetailDTO.getStore();
			for(StoreDTO storeDTO:storeList) {
				storeNullList=BeanToolsUtils.checkObjFieldIsNull(storeDTO, storeNullCol);
				if(storeNullList.size()>0) {
					colList=this.joinHintMessage(colList, storeNullList);
				}
			}
			
			//对地址字段进行验证
			List<AddressesDTO> addressesList=buyerOrganDetailDTO.getAddresses();
			for(AddressesDTO addressesDTO:addressesList) {
				addressNullList=BeanToolsUtils.checkObjFieldIsNull(addressesDTO, adressNullCol);
				if(addressNullList.size()>0) {
					colList=this.joinHintMessage(colList, addressNullList);
				}
			}
			
			if(colList.size()>0) {
				errorMap=this.setValueForErrMap(buyerOrganDetailDTO.getOrgname(),buyerOrganDetailDTO.getMatchid(),colList,commonError);
				errList.add(errorMap);
				colList=new ArrayList<>();
			}
			
		}
	
		return errList;
	}

	/**
	 * 买家信息非空字段验证
	 */
	public List<Map<String, Object>> checkUserData(BaseDTO<List<UserDTO>> baseDTO) throws Exception {
		List<Map<String, Object>> errList=new ArrayList<>();
		Map<String, Object> errorMap=new HashMap<>();
		List<String> nullList=new ArrayList<>();
		List<String> colList=new ArrayList<>();
		
		List<UserDTO> userDTOs=baseDTO.getData();
		
		//得到要验证非空的字段
		String[] nullCol=new String[] {"matchid","loginname","name","moflag","tel","disabledflag","organIds"};
		
		for(UserDTO userDTO:userDTOs) {
			//对字段进行验证
			nullList=BeanToolsUtils.checkObjFieldIsNull(userDTO, nullCol);
			
			if(nullList.size()>0) {
				colList=this.joinHintMessage(colList, nullList);
			}		
			
			if(colList.size()>0) {
				errorMap=this.setValueForErrMap(userDTO.getLoginname(),userDTO.getMatchid(),colList,commonError);
				errList.add(errorMap);
				colList=new ArrayList<>();
			}
			
		}
	
		return errList;
	}

	/**
	 * 卖家机构信息验证
	 */
	public List<Map<String, Object>> checkSellerOrganData(BaseDTO<List<SellerOrganDTO>> baseDTO) throws Exception {
		List<Map<String, Object>> errList=new ArrayList<>();
		Map<String, Object> errorMap=new HashMap<>();
		List<String> nullList=new ArrayList<>();
		List<String> colList=new ArrayList<>();
		
		List<SellerOrganDTO> sellerOrganDTOs=baseDTO.getData();
		
		//得到要验证非空的字段
		String[] nullCol=new String[] {"orgname","orgcode","matchid","type","parentid","store","stopflag","address",
				"tel","linkman","area","province","city","entname","hiddenflag","sendamount",
				"freight","freightamount","freightstep","freightstepamount","paymode"};
		
		for(SellerOrganDTO sellerOrganDTO:sellerOrganDTOs) {
			//对字段进行验证
			nullList=BeanToolsUtils.checkObjFieldIsNull(sellerOrganDTO, nullCol);
			
			if(nullList.size()>0) {
				colList=this.joinHintMessage(colList, nullList);
			}	
			
			if(colList.size()>0) {
				errorMap=this.setValueForErrMap(sellerOrganDTO.getOrgname(),sellerOrganDTO.getMatchid(),colList,commonError);
				errList.add(errorMap);
				colList=new ArrayList<>();
			}
			
		}
	
		return errList;
	}
	
	/**
	 * 商品非空字段验证
	 */
	public List<Map<String, Object>> checkProductInfoData(BaseDTO<List<ProductDataDTO>> baseDTO) throws Exception {
		boolean stopFlag=true;
		List<Map<String, Object>> errList=new ArrayList<>();
		Map<String, Object> errorMap=new HashMap<>();
		List<String> nullList=new ArrayList<>();
		List<String> detailNullList=new ArrayList<>();
		List<String> propertiesNullList=new ArrayList<>();
		List<String> propertiesDetailsNullList=new ArrayList<>();
		List<String> propertiesValueNullList=new ArrayList<>();
		List<String> colList=new ArrayList<>();
		
		//得到要验证非空的字段
		String[] nullCol=new String[] {"shopid","details"};
		String[] detailNullCol=new String[] {"goodsid","name","goodsclassid","matchid","hiddenflag",
				"sendlvl","freightflag","freight","freightamount","freightstep","freightstepamount",
				"goodsproperties","goodspropertiesvalue"};
		String[] propertiesNullCol=new String[] {"id","details"};
		String[] propertiesDetailsNullCol=new String[] {"pertiesid","pertiesname"};
		String[] propertiesValueNullCol=new String[] {"ids","salestate","saleamount","defaultprice","standardweight","defaultflag"};
		
		//验证的数据源
		List<ProductDataDTO> productDataDTOs=baseDTO.getData();
		for(ProductDataDTO pdDTO:productDataDTOs) {
			if(stopFlag) {
				nullList=BeanToolsUtils.checkObjFieldIsNull(pdDTO, nullCol);
				if(nullList.size()>0) {
					colList=this.joinHintMessage(colList, nullList);
					stopFlag=false;
					errorMap=this.setValueForErrMap(null,null,colList,commonError);
					errList.add(errorMap);
					colList=new ArrayList<>();
				}	
			}
			
			List<ProductDTO> ProductDTOs=pdDTO.getDetails();
			if(ProductDTOs!=null) {
				for(ProductDTO productDTO:ProductDTOs) {
					//对字段进行验证
					detailNullList=BeanToolsUtils.checkObjFieldIsNull(productDTO, detailNullCol);
										
					if(detailNullList.size()>0) {
						colList=this.joinHintMessage(colList, detailNullList);
					}
					
					List<GoodsPropertiesDTO> goodsPropertiesList=productDTO.getGoodsproperties();
					if(goodsPropertiesList!=null) {
						for(GoodsPropertiesDTO goodsPropertiesDTO:goodsPropertiesList) {
							propertiesNullList=BeanToolsUtils.checkObjFieldIsNull(goodsPropertiesDTO, propertiesNullCol);
							if(propertiesNullList.size()>0) {
								colList=this.joinHintMessage(colList, propertiesNullList);
							}
							
							List<GoodsPropertiesDetailsDTO> goodsPropertiesDetailsList=goodsPropertiesDTO.getDetails();
							for(GoodsPropertiesDetailsDTO goodsPropertiesDetailsDTO:goodsPropertiesDetailsList) {
								propertiesDetailsNullList=BeanToolsUtils.checkObjFieldIsNull(goodsPropertiesDetailsDTO, propertiesDetailsNullCol);
								if(propertiesDetailsNullList.size()>0) {
									colList=this.joinHintMessage(colList, propertiesDetailsNullList);
								}
							}
							
						}	
					}
					
					List<GoodsproPertiesValueDTO> goodsproPertiesValueList=productDTO.getGoodspropertiesvalue();
					if(goodsproPertiesValueList!=null) {
						for(GoodsproPertiesValueDTO goodsproPertiesValueDTO:goodsproPertiesValueList) {
							propertiesValueNullList=BeanToolsUtils.checkObjFieldIsNull(goodsproPertiesValueDTO, propertiesValueNullCol);
							if(propertiesValueNullList.size()>0) {
								colList=this.joinHintMessage(colList, propertiesValueNullList);
							}
						}
					}
					
					if(colList.size()>0) {
						errorMap=this.setValueForErrMap(productDTO.getName(),productDTO.getMatchid(),colList,commonError);
						errList.add(errorMap);
						colList=new ArrayList<>();
					}
				}
			}
		}

		return errList;
	}

	/**
	 * 商品对应不同的客户的价格的非空个字段验证
	 */
	public List<Map<String, Object>> checkProductPriceInfoData(BaseDTO<List<ProductPriceDataDTO>> baseDTO) throws Exception {
		List<Map<String, Object>> errList=new ArrayList<>();
		Map<String, Object> errorMap=new HashMap<>();
		List<String> nullList=new ArrayList<>();
		List<String> detailNullList=new ArrayList<>();
		List<String> propertiesNullList=new ArrayList<>();
		List<String> propertiesDetailsNullList=new ArrayList<>();
		List<String> propertiesValueNullList=new ArrayList<>();
		List<String> colList=new ArrayList<>();
		
		//得到要验证非空的字段
		String[] nullCol=new String[] {"shopid","details"};
		String[] detailNullCol=new String[] {"goodsid","goodsname","matchid","cussyscode"};
		String[] propertiesNullCol=new String[] {"id","details"};
		String[] propertiesDetailsNullCol=new String[] {"pertiesid","pertiesname"};
		String[] propertiesValueNullCol=new String[] {"ids","productprice","validbegindate","validenddate"};
		
		//验证的数据源
		List<ProductPriceDataDTO> productPriceDataDTO=baseDTO.getData();
	
			for(ProductPriceDataDTO pdDTO:productPriceDataDTO) {
				nullList=BeanToolsUtils.checkObjFieldIsNull(pdDTO, nullCol);
				if(nullList.size()>0) {
					colList=this.joinHintMessage(colList, nullList);
					errorMap=this.setValueForErrMap(null,null,colList,commonError);
					errList.add(errorMap);
					colList=new ArrayList<>();
				}	
				
				
				List<ProductPriceDTO> productPriceDTOs=pdDTO.getDetails();	
				if(productPriceDTOs!=null) {
					for(ProductPriceDTO productPriceDTO:productPriceDTOs) {
						//对字段进行验证
						detailNullList=BeanToolsUtils.checkObjFieldIsNull(productPriceDTO, detailNullCol);
											
						if(detailNullList.size()>0) {
							colList=this.joinHintMessage(colList, detailNullList);
						}
						
						List<ProductPricePropertiesDTO> productPricePropertiesList=productPriceDTO.getGoodsproperties();
						if(productPricePropertiesList!=null) {
							for(ProductPricePropertiesDTO productPricPropertiesDTO:productPricePropertiesList) {
								propertiesNullList=BeanToolsUtils.checkObjFieldIsNull(productPricPropertiesDTO, propertiesNullCol);
								if(propertiesNullList.size()>0) {
									colList=this.joinHintMessage(colList, propertiesNullList);
								}
								
								List<ProductPricePropertiesDetailsDTO> productPricePropertiesDetailsList=productPricPropertiesDTO.getDetails();
								for(ProductPricePropertiesDetailsDTO productPricePropertiesDetailsDTO:productPricePropertiesDetailsList) {
									propertiesDetailsNullList=BeanToolsUtils.checkObjFieldIsNull(productPricePropertiesDetailsDTO, propertiesDetailsNullCol);
									if(propertiesDetailsNullList.size()>0) {
										colList=this.joinHintMessage(colList, propertiesDetailsNullList);
									}
								}
								
							}				
						}
						
						List<ProductPricePertiesValueDTO> productPricePertiesValueDTOList=productPriceDTO.getGoodspropertiesvalue();
						if(productPricePertiesValueDTOList!=null) {
							for(ProductPricePertiesValueDTO productPricepertiesValueDTO:productPricePertiesValueDTOList) {
								propertiesValueNullList=BeanToolsUtils.checkObjFieldIsNull(productPricepertiesValueDTO, propertiesValueNullCol);
								if(propertiesValueNullList.size()>0) {
									colList=this.joinHintMessage(colList, propertiesValueNullList);
								}
							}
						}
						
						if(colList.size()>0) {
							errorMap=this.setValueForErrMap(productPriceDTO.getGoodsname(),productPriceDTO.getMatchid(),colList,commonError);
							errList.add(errorMap);
							colList=new ArrayList<>();
						}
					}
				}
			}
		
		return errList;
	}
	
	/**
	 * 商品于客户的对应关系非空字段验证
	 */
	public List<Map<String, Object>> checkProductCustomerInfoData(BaseDTO<List<ProductCustomerDataDTO>> baseDTO) throws Exception{
		List<Map<String, Object>> errList=new ArrayList<>();
		Map<String, Object> errorMap=new HashMap<>();
		List<String> nullList=new ArrayList<>();
		List<String> detailsNullList=new ArrayList<>();
		List<String> pcgNullList=new ArrayList<>();
		List<String> colList=new ArrayList<>();
		
		//得到要验证非空的字段
		String[] nullCol=new String[] {"shopid","details"};
		String[] detailNullCol=new String[] {"cussyscode","customername","details"};
		String[] pcgNullCol=new String[] {"matchid"};
		
		//验证的数据源
		List<ProductCustomerDataDTO> productCustomerDataDTOs=baseDTO.getData();
		
		for(ProductCustomerDataDTO pcDTO:productCustomerDataDTOs) {
			nullList=BeanToolsUtils.checkObjFieldIsNull(pcDTO, nullCol);
			if(nullList.size()>0) {
				colList=this.joinHintMessage(colList, nullList);
				errorMap=this.setValueForErrMap(null,null,colList,commonError);
				errList.add(errorMap);
				colList=new ArrayList<>();
			}	
			
			List<ProductCustomerDetailsDTO> productCustomerDetailsDTOs=pcDTO.getDetails();
			if(productCustomerDetailsDTOs!=null) {
				for(ProductCustomerDetailsDTO pcdDTO:productCustomerDetailsDTOs) {
					detailsNullList=BeanToolsUtils.checkObjFieldIsNull(pcdDTO, detailNullCol);
					if(detailsNullList.size()>0) {
						colList=this.joinHintMessage(colList, detailsNullList);
					}
					
					List<ProductCustomerGoodsDTO> productCustomerGoodsDTOs=pcdDTO.getDetails();
					if(productCustomerGoodsDTOs!=null) {
						for(ProductCustomerGoodsDTO pcgDTO:productCustomerGoodsDTOs) {
							pcgNullList=BeanToolsUtils.checkObjFieldIsNull(pcgDTO, pcgNullCol);
							if(pcgNullList.size()>0) {
								colList=this.joinHintMessage(colList, pcgNullList);
							}
						}
					}
					
					if(colList.size()>0) {
						errorMap=this.setValueForErrMap(pcdDTO.getCustomername(),pcdDTO.getCussyscode()==null?"":pcdDTO.getCussyscode().toString(),colList,commonError);
						errList.add(errorMap);
						colList=new ArrayList<>();
					}
					
				}
			}
			
		}
		
		return errList;
	}
	
	/**
	 * 地址类信息要与商城的代码一致，不一致则返回错误信息
	 */
	public List<Map<String, Object>> checkAdministrativeArea(SellerOrganDTO dto,
			List<SellerOrganDTO> soDTOList,List<Map<String, Object>> errList) throws Exception {
		Map<String, String> map = codeTransformUtils.getAreaName(dto.getProvince());
		String cityName=codeTransformUtils.getCityName(dto.getCity());
		
		if(map == null || map.size() == 0) {	//省代码不对
			List<String> infoList=new ArrayList<>();
			infoList.add(msu.getMessage("match.validate.uperr.province", null));
			Map<String, Object> errMap=this.setValueForErrMap(dto.getOrgname(), dto.getMatchid(), infoList,dataError);
			errList.add(errMap);
			
		}else {
			if(dto.getArea() == null || !dto.getArea().equals(map.get("areaCode"))) {	//区域代码不对
				List<String> infoList=new ArrayList<>();
				infoList.add(msu.getMessage("match.validate.uperr.area", null));
				Map<String, Object> errMap=this.setValueForErrMap(dto.getOrgname(), dto.getMatchid(),infoList,dataError);
				errList.add(errMap);
				
			}
		}
		
		if(StringUtils.isBlank(cityName)) {	//市代码不对
			List<String> infoList=new ArrayList<>();
			infoList.add(msu.getMessage("match.validate.uperr.city", null));
			Map<String, Object> errMap=this.setValueForErrMap(dto.getOrgname(), dto.getMatchid(),infoList,dataError);
			errList.add(errMap);
		}
		
		return errList;
	}	
	
	
	public List<String> joinHintMessage(List<String> colList,List<String> nullList) {
		for(String col:nullList) {
			String colName=msu.getMessage(col, null);
			colList.add(msu.getMessage("match.validate.colNull", new String[] {colName+"("+col+")"}));
		}
		return colList;
	}	

	/**
	 * 客户价格时间段的验证
	 */
	public List<Map<String, Object>> checkDateOfProductPrice(List<Map<String, Object>> errList,BaseDTO<List<ProductPriceDataDTO>> baseDTO) throws Exception{
		List<ProductPriceDataDTO> productPriceDataDTOs=baseDTO.getData();
		
		for(ProductPriceDataDTO ppdDTO:productPriceDataDTOs) {	

			List<ProductPriceDTO> productPriceDTOs=ppdDTO.getDetails();
			for(ProductPriceDTO ppDTO:productPriceDTOs) {
				Map<String, Object> dateMap=new HashMap<>();
				List<Map<String, Object>> dateList=new ArrayList<>();
				
				String goodsName=ppDTO.getGoodsname();
				String cusName=ppDTO.getCusname();
				
				List<ProductPricePertiesValueDTO> productPricePertiesValueDTOs=ppDTO.getGoodspropertiesvalue();
				for(ProductPricePertiesValueDTO ppvDTO:productPricePertiesValueDTOs) {
					String beginDate=ppvDTO.getBegindate();
					String endDate=ppvDTO.getEnddate();
					String ppId=ppvDTO.getPpmatchid();

					//验证日期格式是否正确
					boolean beginDateFlag=this.checkDateFormat(beginDate);
					if(!beginDateFlag) {
						errList=this.dateFormatErrorInfo(errList, cusName, ppId,msu.getMessage("begindate", null));
					}
					boolean endDateFlag=this.checkDateFormat(endDate);
					if(!endDateFlag) {
						errList=this.dateFormatErrorInfo(errList, cusName, ppId,msu.getMessage("begindate", null));
					}
					
					if(beginDateFlag&&endDateFlag) {
						Long bDate=sdf.parse(beginDate).getTime();
						Long eDate=sdf.parse(endDate).getTime();
						
						errList=this.dateCompareOfProductPrice(errList, bDate, eDate, dateList, goodsName, cusName,ppId);
						
						dateMap.put("bDate", bDate);
						dateMap.put("eDate", eDate);
						dateList.add(dateMap);
					}
					
				}
			}
			
		}
		
		return errList;
	} 

	@Override
	public boolean checkDateFormat(String date){
		boolean resultFlag=true;
		try {
			sdf.parse(date);
		} catch (ParseException e) {
			resultFlag=false;
		}
		
		return resultFlag;
	}
	
	@Override
	public List<Map<String, Object>> dateFormatErrorInfo(List<Map<String, Object>> errList,String titleName,String titleId,String dateName){
		List<String> infoList=new ArrayList<>();
		infoList.add(msu.getMessage("match.validate.dateFormat", new String[] {dateName}));
		Map<String, Object> errMap=this.setValueForErrMap(titleName, titleId,infoList,commonError);
		errList.add(errMap);
		
		return errList;
	}
	
	public List<Map<String, Object>> dateCompareOfProductPrice(List<Map<String, Object>> errList,
			Long bDate,Long eDate,List<Map<String, Object>> dateList,String goodsName,String cusName,String ppId){
		
		//开始时间不能大于结束时间
		if(bDate>eDate) {		
			List<String> infoList=new ArrayList<>();
			infoList.add(msu.getMessage("match.validate.beCompare", new String[] {cusName,goodsName}));
			Map<String, Object> errMap=this.setValueForErrMap(cusName, ppId,infoList,commonError);
			errList.add(errMap);
			
		}
		
		//日期不能有重叠
		if(dateList.size()>0) {
			for(Map<String, Object> dateMap:dateList) {
				Long oldEndDate=(Long) dateMap.get("eDate");
				if(bDate<oldEndDate) {
					List<String> infoList=new ArrayList<>();
					infoList.add(msu.getMessage("match.validate.dateStacking", new String[] {cusName,goodsName}));
					Map<String, Object> errMap=this.setValueForErrMap(cusName, ppId,infoList,commonError);
					errList.add(errMap);
					break;
				}
			}
		}
		
		
		return errList;
	}

	@Override
	public BaseDTO<String> setValueTobaseDTO(String datas) throws org.json.JSONException{
		JSONObject jo=new JSONObject(datas);
		
		BaseDTO<String> baseDTO=new BaseDTO<>();
		Long registerCode=jo.getLong("registercode");
		String registerTel=jo.getString("registertel");
		String enterpriseId=jo.getString("enterpriseid");
		baseDTO.setRegistercode(registerCode);
		baseDTO.setRegistertel(registerTel);
		baseDTO.setEnterpriseid(enterpriseId);
		baseDTO.setData("");
		
		return baseDTO;
	}
	
}
